What is node-libs-browser?
The node-libs-browser package is a collection of browser-friendly versions of Node.js core modules. It allows developers to use Node.js-style modules in the browser, providing shims and polyfills for Node.js core modules that do not have direct equivalents in the browser environment. This package is particularly useful for bundling applications with webpack, which uses it to simulate a Node.js environment in the browser.
What are node-libs-browser's main functionalities?
Buffer
Provides a Buffer class that can be used for binary data manipulation in the browser, similar to Node.js's Buffer module.
var Buffer = require('buffer/').Buffer;
var buf = Buffer.from('hello world', 'ascii');
console.log(buf.toString('hex'));
Events
Implements the EventEmitter class to enable event-driven architecture in the browser, mimicking Node.js's events module.
var EventEmitter = require('events/').EventEmitter;
var emitter = new EventEmitter();
emitter.on('event', function(message) {
console.log(message);
});
emitter.emit('event', 'Hello world!');
Path
Provides utilities for file path operations, similar to Node.js's path module, but adapted for the browser.
var path = require('path-browserify');
console.log(path.basename('/foo/bar/baz/asdf/quux.html'));
Other packages similar to node-libs-browser
browserify
Browserify lets you require('modules') in the browser by bundling up all of your dependencies. It's similar to node-libs-browser in that it allows Node.js code to run in the browser, but it works at the bundling level, transforming Node.js modules into browser-compatible scripts.
webpack-node-externals
This package is used with webpack to automatically exclude node modules. It's related to node-libs-browser in the context of building for the browser, but instead of providing browser versions of Node.js modules, it helps to avoid bundling them altogether.
crypto-browserify
A port of Node.js's crypto module to the browser. It offers similar functionality to one aspect of node-libs-browser, focusing specifically on cryptographic functions.
node-libs-browser
The node core libs for in-browser usage.
NOTE: This library is deprecated and won't accept Pull Requests that include Breaking Changes or new Features. Only bugfixes are accepted.
Exports a hash [object] of absolute paths to each lib, keyed by lib names. Modules without browser replacements are null
.
Some modules have mocks in the mock
directory. These are replacements with minimal functionality.
Outdated versions
buffer
The current buffer
implementation uses feross/buffer@4.x because feross/buffer@5.x relies on typed arrays.
This will be dropped as soon as IE9 is not a typical browser target anymore.
punycode
The current punycode
implementation uses bestiejs/punycode.js@1.x because bestiejs/punycode.js@2.x requires modern JS engines that understand const
and let
.
It will be removed someday since it has already been deprecated from the node API.
License
MIT